package com.huang.tiger.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Calendar;
import java.util.Date;

/**
 * JWT 工具类
 */
public class JwtUtils {



    public static String createToken(String userId,String name,String tel) {

        Calendar nowTime = Calendar.getInstance();
        nowTime.add(Calendar.MINUTE,30);
        Date expiresDate = nowTime.getTime();
        String token = JWT.create().withAudience(userId)   //签发对象
                .withIssuedAt(new Date())    //发行时间
                .withExpiresAt(expiresDate)  //有效时间
                .withClaim("name", name)    //载荷，随便写几个都可以
                .withClaim("tel", tel)
                .withClaim("userId", userId)
                .sign(Algorithm.HMAC256(userId + "HelloLehr"));//加密
        return token;
    }

}
